home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3699 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: The size of a file
  5. Date: 30 Jan 1996 18:44:43 GMT
  6. Organization: Computer People Inc.
  7. Message-ID: <ALUN.CHAMPION.96Jan30134443@g7240065.bridge.bst.bls.com>
  8. References: <4ebc03$4gv@gate.compart.fi> <59.28250.5782@windmill.com>
  9.     <4elf3v$s5o@noc.tor.hookup.net>
  10. NNTP-Posting-Host: bstfirewall.bst.bls.com
  11. In-reply-to: Richard Steadman's message of 30 Jan 1996 15:56:47 GMT
  12.  
  13. In article <4elf3v$s5o@noc.tor.hookup.net> Richard Steadman <rsteadma@mmltd.com> writes:
  14. : charlie.brown@windmill.com (Charlie Brown) wrote:
  15. :> [* Original attribution lost *]
  16. :>> This is driving me nuts.  I can't find a simple way to get the size of a
  17. :>> disk file.  This must be possible using the standard C library, but I
  18. :>> haven't figured out how!
  19. :> 
  20. :> This works with MSC, Borland may have a different name
  21. :> for _dos_findfirst().
  22. :> 
  23. :> #include <dos.h>
  24. :> long fsize(filespec)
  25. :> char *filespec;
  26. :> {
  27. :>         struct find_t fileinfo;
  28. :> 
  29. :>         if(0 ==  _dos_findfirst(filespec,0,&fileinfo))
  30. :>                 return fileinfo.size;
  31. :>         else
  32. :>                 return 0L;
  33. :> }
  34.  
  35. But this doesn't answer his question. He wanted to use the standard C library
  36. and _dos_findfirst() is not in the ANSI spec.
  37.  
  38. The usual method is to fopen() a file in binary mode and fseek() to the
  39. end and the use the result of ftell() as the file size. Though the standard
  40. allows this not to work for some binary streams (see fseek() description) it
  41. practise if the stream is attached to a file then it should work.
  42.  
  43. : But there's no way to get the file size if its length is greater
  44. : than will fit in a long int?
  45.  
  46. The minimum size for long int is 4 bytes - this is only a minimum it can
  47. be bigger.
  48. Maximum value for 4 byte long is 2147483647 which is 2 gigabytes, in practise
  49. not many files will break this limit. In fact your operating system may not
  50. be able to deal with files bigger than this.
  51.  
  52. Regards
  53.  
  54.    -A.
  55.  
  56.  
  57. -- 
  58. | A.Champion                |
  59.